<?php
include_once '../../lib/config.php';
include_once '../../lib/db.php';
include '../../lib/utils/date.php';
include '../../lib/utils/tag.php';
include '../../model/rangking.php';
include '../../model/karyawan.php';

$proc = $_REQUEST['proc'];

switch ($proc):
case 'rank-table':
	$startPeriode = $_REQUEST['startPeriode'];
	$endPeriode = $_REQUEST['endPeriode'];
	$orderby = $_REQUEST['orderby'];
	
	if ($startPeriode>$endPeriode) {
		$tmp = $startPeriode;
		$startPeriode = $endPeriode;
		$endPeriode = $tmp;
	}
	
	$startYear = date("Y", $startPeriode);
	$startMonth = date("m", $startPeriode);
	$endYear = date("Y", $endPeriode);
	$endMonth = date("m", $endPeriode);
	
	for($year=$startYear; $year<=$endYear; $year++){	
		if ($startYear == $endYear){
			rankTable_loadTable($startMonth, $endMonth, $year);
		}
		else {
			rankTable_loadTable($startMonth, 12, $year);
			$startMonth = 1;
		}
	}
break;
	
endswitch;

function rankTable_loadTable($startMonth, $endMonth, $year){
	for($month=$startMonth; $month<=$endMonth; $month++){
		rank_ranked($month, $year);
		$orderby = $_REQUEST['orderby'];
		include '../../view/admin/ranking/tablelist.php';
	}
}